package com.wlr.study.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author HustleLr
 * @version 1.0.0
 * @date 2023/10/25 19:31
 * @describe LeetCode228
 */
public class LeetCode228 {

    public List<String> summaryRanges(int[] nums) {
        int length = nums.length, j = 0;
        List<String> result = new ArrayList<>();
        for (int i = 1; i < length; i++) {
            if (nums[i] - 1 > nums[i - 1]) {
                result.add(j == i - 1 ? nums[j] + "" : nums[j] + "->" + nums[i - 1]);
                j = i;
            }
        }
        if (j < nums.length) {
            result.add(j == nums.length - 1 ? nums[j] + "" : nums[j] + "->" + nums[nums.length - 1]);
        }
        return result;
    }

    public static void main(String[] args) {

    }
}
